<template>
  <div>
    <request-tool :env="apiStore.env" @save="onSaveSubmit" ref="requestToolComponent" />
  </div>
</template>

<script>
import RequestTool from "@/components/RequestTool/index.vue";
import { onMounted, ref } from "@vue/composition-api";
import { useApiStore } from "@/store/api";
import { createInstance, fetchInstancePage } from "@/api/api";
export default {
  components: {
    RequestTool,
  },
  setup() {
    const requestToolComponent = ref(null);
    const apiStore = useApiStore();
    const envList = [
      {
        name: "天津正式环境",
        url: "http://localhost:50000",
      },
      {
        name: "天津开发环境",
        url: "http://10.67.70.169",
      },
    ];
    onMounted(() => {
        requestToolComponent.value.setDoc(apiStore.doc, envList);
    })

    function onSaveSubmit(doc, resolve) {
      if (apiStore.docId > 0) {
        console.log(doc)
        doc.summary = apiStore.doc.summary
        doc.projectId = apiStore.projectId
        doc.docId = apiStore.docId
        createInstance(doc).finally(() => {
          resolve();
        });
        // apiStore.saveQuickDoc(doc).finally(() => {
        //   resolve();
        // });
      } else {
        tmpDoc = doc;
        visible.value = true;
        resolve();
      }
    }

    function setInstance(instance) {
      console.log(instance)
      requestToolComponent.value.setQuickDoc(instance, envList)
    }

    return {
      requestToolComponent,
      apiStore,
      onSaveSubmit,
      /**@public */
      setInstance
    };
  },
};
</script>

<style scoped>
</style>